package net.hn.hnms.biz.gasext.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.hn.hnms.biz.gasext.domain.dto.AnalysisDataDto;
import net.hn.hnms.biz.gasext.domain.dto.HisDto;
import net.hn.hnms.biz.gasext.domain.dto.NowDto;
import net.hn.hnms.biz.gasext.domain.dto.PointDto;
import net.hn.hnms.biz.gasext.domain.vo.*;
import net.hn.hnms.biz.gasext.service.GasExtractionService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: QueryPivotController
 * @Description 瓦斯抽采数据查询
 * @Author 王龙
 * @Date 2022-09-28
 * @Version 0.1
 */
@Api(value = "瓦斯抽采数据查询制器", tags = {"瓦斯抽采数据查询"})
@RestController
@RequestMapping("/QueryPivot")
@RequiredArgsConstructor
public class QueryPivotController {
    @Resource
    private GasExtractionService gasExtractionService;

    /**
     * 获取所属设备下拉列表
     * @return
     */
    @ApiOperation("获取所属设备下拉列表")
    @GetMapping("categoryList")
    @AutoSetMineCode
    public R categoryList(@ApiParam(value = "煤矿编码") String mineCode) {
        List<String> list = gasExtractionService.categoryList(mineCode);
        return R.ok(list);
    }

    /**
     * * 分页条件查询实时数据
     * @param pageQuery
     * @param nowDTO
     * @return
     */
    @ApiOperation("分页条件查询实时数据")
    @GetMapping("pageNowList/pageList")
    @AutoSetMineCode
    public R<ResponsePage<NowVo>> pageNowList(PageQuery pageQuery, NowDto nowDTO) {
        ResponsePage<NowVo> list = gasExtractionService.pageNowList(pageQuery, nowDTO);
        return R.ok(list);
    }
    /**
     * * 分页条件查询历史数据
     *
     * @param pageQuery
     * @param hisDTO
     * @return
     */
    @ApiOperation("分页条件查询历史数据")
    @GetMapping("pageHistoryInfo/pageList")
    @AutoSetMineCode
    public R<ResponsePage<HisVo>> pageHistoryInfo(PageQuery pageQuery, HisDto hisDTO) {
        ResponsePage<HisVo> page = gasExtractionService.pageHistoryInfo(pageQuery, hisDTO);
        return R.ok(page);
    }
    /**
     * * 弹窗曲线
     * @return
     */
    @ApiOperation("弹窗曲线")
    @GetMapping("popup")
    @AutoSetMineCode
    public R<PopupVo> popup(@ApiParam(value = "工混流量|工混累计量|标纯累计量") String name, @ApiParam(value = "煤矿编码") String mineCode) {
        PopupVo popupVo = gasExtractionService.popup(name,mineCode);
        return R.ok(popupVo);
    }
    @ApiOperation("条件查询历史数据测点曲线")
    @GetMapping("pointHistoryCurve")
    @AutoSetMineCode
    public R<ChartDateVo> pointHistoryCurve(PointDto pointDto) {
        //开始时间  若为空默认为前6小时的日期 >=data_time
        if (pointDto.getStartTime() == null) {
            Calendar instance = Calendar.getInstance();
            instance.setTime(new Date());
            //日期减6小时
            instance.add(Calendar.HOUR_OF_DAY, -6);
            pointDto.setStartTime(instance.getTime());
        }
        if  (pointDto.getEndTime() == null) {
            pointDto.setEndTime(new Date());
        }
        if (pointDto.getEndTime().getTime() - pointDto.getStartTime().getTime() > (3600 * 24 * 31 * 1000L)) {
            //1月得数据
            return R.fail("请选择1月内时间范围");
        }
        ChartDateVo chartDateVo= gasExtractionService.pointHistoryCurve(pointDto);
        return R.ok(chartDateVo);
    }
    @ApiOperation("条件查询历史数据测点列表")
    @GetMapping("pointHistoryList")
    @AutoSetMineCode
    public R<List<PointHistoryListVo>> pointHistoryList(PointDto pointDto) {
        //开始时间  若为空默认为前6小时的日期 >=data_time
        if (pointDto.getStartTime() == null) {
            Calendar instance = Calendar.getInstance();
            instance.setTime(new Date());
            //日期减6小时
            instance.add(Calendar.HOUR_OF_DAY, -6);
            pointDto.setStartTime(instance.getTime());
        }
        if  (pointDto.getEndTime() == null) {
            pointDto.setEndTime(new Date());
        }
        if (pointDto.getEndTime().getTime() - pointDto.getStartTime().getTime() > (3600 * 24 * 31 * 1000L)) {
            //1月得数据
            return R.fail("请选择1月内时间范围");
        }
        List<PointHistoryListVo> list= gasExtractionService.pointHistoryList(pointDto);
        return R.ok(list);
    }

    @ApiOperation("综合防治-关联系统-瓦斯抽采系统重点指标")
    @AutoSetMineCode
    @GetMapping("/keyGasIndex")
    public R<List<AnalysisDataDto>> keyGasIndex() {
        return R.ok(gasExtractionService.keyGasIndex());
    }


}
